//
//  BaseNavigationController.m
//  Water
//
//  Created by reyzhang on 2021/2/2.
//  Copyright © 2021 myjs. All rights reserved.
//

#import "BaseNavigationController.h"

@interface BaseNavigationController () 

@end

@implementation BaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
 
    if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
        [appearance configureWithOpaqueBackground];
        appearance.backgroundColor = [UIColor whiteColor];
        appearance.shadowColor = [UIColor clearColor];
        self.navigationBar.standardAppearance = appearance;
        self.navigationBar.scrollEdgeAppearance=self.navigationBar.standardAppearance;
    }else {
        
        [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
        [self.navigationController.navigationBar setShadowImage:nil];
    }

}



#pragma mark UINavigationControllerDelegate
//拦截push进来的控制器
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
//      修改push过去的界面
    if ((self.childViewControllers.count > 0)) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"Nav_Back"] forState:UIControlStateNormal];
//        [button setEnlargedEdgeWithTop:kEdgeDistance_10 left:kEdgeDistance_20 bottom:kEdgeDistance_10 right:kEdgeDistance_10];
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        button.size = CGSizeMake(25, 21);
        
        [button addTarget:viewController action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

        // 修改导航栏左边的item
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

        viewController.hidesBottomBarWhenPushed = YES;

    }
    //如果在控制器有设置，就可以让后面设置的按钮可以覆盖它
    [super pushViewController:viewController animated:animated];
    
}

@end
